package com.relax.netty.nio;

import java.nio.IntBuffer;
import java.util.Random;

public class NioTest1 {
    public static void main(String[] args) {

        IntBuffer intBuffer = IntBuffer.allocate(10);
        for (int i = 0; i < 5; i++) {
            int rand = new Random().nextInt(20);
            intBuffer.put(rand);
        }
        System.out.println("step1: byBufPosition:" + intBuffer.position() + ",byBufLimit:" + intBuffer.limit());


        intBuffer.flip();
        System.out.println("step2: byBufPosition:" + intBuffer.position() + ",byBufLimit:" + intBuffer.limit());
        System.out.println(intBuffer.get(4))
        ;


        while (intBuffer.hasRemaining()) {
            int i = intBuffer.get();
            System.out.println(i);
        }
//        System.out.println("step2222: byBufPosition:" + intBuffer.position() + ",byBufLimit:" + intBuffer.limit() );
//        for (int i = 0; i < 6; i++) {
//            int rand = new Random().nextInt(20);
//            intBuffer.put(rand);
//        }

//
//        for (int i = 0; i < 2; i++) {
//            intBuffer.get();
//            System.out.println("stepaaa: byBufPosition:" + intBuffer.position() + ",byBufLimit:" + intBuffer.limit() );
//        }


        intBuffer.flip();
        System.out.println("step3: byBufPosition:" + intBuffer.position() + ",byBufLimit:" + intBuffer.limit());


        for (int i = 0; i < 3; i++) {
            int rand = new Random().nextInt(20);
            intBuffer.put(rand);
        }
        System.out.println("step4: byBufPosition:" + intBuffer.position() + ",byBufLimit:" + intBuffer.limit());

    }
}
